package examplePackage;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class for Servlet: Registrationform
 *
 */
 public class Registrationform extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
    /* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	 private static final long serialVersionUID = 1L;
	public Registrationform() {
		super();
	}   	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
			try
			{
				UserBean1 user = new UserBean1();
				user.setCname(request.getParameter("cname"));
				user.setCid(request.getParameter("cid"));
				user.setEmail_id(request.getParameter("email_id"));
				user.setPhone_no(request.getParameter("phone_no"));
			
				user = UserDAO.register(user);
				if (user.isValid()) 
				{
				HttpSession session = request.getSession(true);
			 	session.setAttribute("currentSessionUser",user);
				response.sendRedirect("welcome.jsp");
				}
				else
				{
					response.sendRedirect("welcome.jsp");
				}
			}
			catch (Throwable theException) 
			{
				System.out.println(theException);
			}
		// TODO Auto-generated method stub
		}  	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}   	  	    
}